package generator.groupclass;

import generator.denpendency.detection.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Group implements Serializable{
	
	//everyone is the same
	 
	public int currentDays;
	
	public int generateDays;

    // everyone has the attribute, but has different values
	 
	public ArrayList<ArrayList<Integer>> groups = new ArrayList<ArrayList<Integer>>();
	
	public LDA[] lda; //every group has a LDA class, how can i do
	
	public int listLength;
	
	public ArrayList<Object> al = new ArrayList<Object>();
	
	//for statistics
	int offset;
	int generateRows;
	
	String theta_;
	String phi_;
	String lp_;
	String lpTemp;
	String key_;
	
	int topicNumbers;
	int lpDimension;
	
	public Group(int currentDays, int generateDays, int generateRows, 
			String theta, String phi, String lp, String lpTemp, String key_,
			int topicNumbers, int lpDimension) {
		
		this.currentDays = currentDays;
		this.generateDays = generateDays;
		this.generateRows = generateRows;
		
		this.theta_ = theta;
		this.phi_ = phi;
		this.lp_ = lp;
		this.lpTemp = lpTemp;
		this.key_ = key_;
	
		this.topicNumbers = topicNumbers;
		this.lpDimension = lpDimension;
	}
	
	/**
	 * get the n-th distribution--n-th element of groups		
	 * @return
	 */
	public ArrayList<Integer> get(int i) {
		ArrayList<Integer> element = groups.get(i);
		return element;
	}
	
	public void setGroup(ArrayList<ArrayList<Integer>> groups) {
		this.groups = groups;
		this.listLength = groups.size();
		
		initialLdaArray();
	}
	
	//==============LDA components=================
	
	public String getPHIfile(int i) {
		String phiFile = "";
		return phiFile;
	}
	
	public String getThetaFile(int i) {
		String thetaFile = "";
		return thetaFile;
	}
	
	public String getLpFile(int i) {
		String lpFile = "";
		return lpFile;
	}
	
	public String getLpTempFile(int i) {
		String lpTempFile = "";
		return lpTempFile;
	}
	
	public String getKeyFile(int i) {
		String keyFile = "";
		return keyFile;
	}
	
	public void initialLdaArray() {
		
		lda = new LDA[listLength];
	}
	
	public void setDistributionRowArray(int i, 
			ArrayList<Map<String, Integer>> currentDistributionList, 
			ArrayList<Integer> rowsArray) {
		
//		System.out.println("circle: ");
//		System.out.println(currentDistributionList);
//		System.out.println(rowsArray);
		
		String phiFile = getPHIfile(i);
		String thetaFile = getThetaFile(i);
		String lpFile = getLpFile(i);
		String lpTempFile = getLpTempFile(i);
		String keyFile = getKeyFile(i);
		
		lda[i] = new LDA(currentDays, generateDays, currentDistributionList, rowsArray, generateRows, topicNumbers, lpDimension);
		
		lda[i].setFile(phiFile, thetaFile, lpFile, lpTempFile, keyFile);
		
	}
	
//	public void LDAinference() {
//		
//		for(int i = 0; i < listLength; i++) {
//			LDA ldaTemp = lda[i];
//			
//			if(ldaTemp.getGenerateDay() == currentDays - 1){
//				ldaTemp.setCategory(1);
//			} 
//			
//			ldaTemp.addGenerateDay();
//			ldaTemp.compute();
//			
//		}
//	}

	
	public void LDAcompute(int i) {
//		for(int i = 0; i < listLength; i++) {
			lda[i].compute();
//		}
	}
	
	public void LDAfastCompute(int i) {
		
		//for(int i = 0; i < listLength; i++) {
			lda[i].fastCompute();
		//}
		
	}
	
//	public void LDAfastCompute(int i) {
//		
//		lda[i] = new LDA(currentDays, generateDays, currentDistributionList, rowsArray, generateRows);
//		
//		String phiFile = getPHIfile(i);
//		String thetaFile = getThetaFile(i);
//		String lpFile = getLpFile(i);
//		
//		lda[i].setFile(phiFile, thetaFile, lpFile);
//		
//		lda[i].fastCompute();
//		
//	}
	
	//=============Statistics: distinct and id=====================
	public ArrayList<ArrayList<Integer>> getGroups() {
		return groups;
	}
	
	public int getListLength() {
		
		return listLength;
	}
	
	public int[] getDistinct() {
		
		int[] distinctArray = new int[listLength];
		
		for(int i = 0; i < listLength; i++) {
			distinctArray[i] = lda[i].getDistinct();
		}
		
		return distinctArray;
	}
	
	public void setOffset(int offset) {
		this.offset = offset;
	}
	
	public void recordIDNode(int i, String ip) {
		
	}
	
}
